<?php

namespace LEA\StageBundle\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use LEA\StageBundle\SQL\queriesEtapes;
use LEA\StageBundle\SQL\queries;
use LEA\UserBundle\SQL\dbmngt\queriesEtud;

class EtudMajInfoController extends Controller
{
    public function indexAction($user)
    {
    	$conn = $this->container->get('database_connection');

    	$request = $this->getRequest();
		$session = $request->getSession();

		$refYear = $session->get('REF_YEAR');


        if ($request->getMethod() == 'POST') {
            $form->bind($request);

            if ($form->isValid()) {
            }
        }

    	$array = $this->etudiantArray($conn, $user, $refYear, $session) ;
		return $this->render('LEAStageBundle:Etud:majInfo.html.php', $array) ;
    }

	private function etudiantArray($conn, $student, $refYear, $session){
		$queriesEtapes = new QueriesEtapes($conn);
		$queriesEtud = new QueriesEtud($conn);
		$queries = new Queries($conn, $session);

		$altRef=$queriesEtud->doGetAltRefForStudent($student,$refYear,$session);
		$alts = $queriesEtapes->doQueryRenduEtape0($altRef) ;
		$entreprises = $queries->doQueryListEntr() ;
		$regies = $queries->doQueryListEntr() ;

		$alt = $alts->fetch() ;
		$entrepriseCle = $alt['entrepriseCle'] ;
		$entrepriseRegieCle = $alt['entrepriseRef'] ;
		$bureaux = $queries->doQueryListBureau($entrepriseCle) ;
		$bureauxAlt = $queries->doQueryListBureau($entrepriseRegieCle) ;

		$referents = $queries-> doQueryListReferent($entrepriseCle) ;
		$referents2 = $queries-> doQueryListReferent($entrepriseCle) ;

		$referentsAlt = $queries-> doQueryListReferent($entrepriseRegieCle) ;
		$referents2Alt = $queries-> doQueryListReferent($entrepriseRegieCle) ;


		$opcas = $queries->doQueryListOPCA();


		return array(
		'user' => $student,
		'refYear' => $refYear,
		'alt' => $alt,
		'alts' => $alts,
		'entreprises' => $entreprises,
		'bureaux' => $bureaux,
		'bureauxAlt' => $bureauxAlt,
		'referents' => $referents,
		'referents2' => $referents2,
		'referentsAlt' => $referentsAlt,
		'referents2Alt' => $referents2Alt,
		'opcas' => $opcas,
		'regies' => $regies);
    }


}
